#pragma once
#include <mysql/mysql.h>
#include <string>
#include <ctime>
using namespace std;

class Connection
{
public:

	Connection();

	~Connection();

	bool connect(string ip, 
		unsigned short port, 
		string user, 
		string password,
		string dbname);

	bool update(const char* );

	MYSQL_RES* query(const char* );

	int getInsertId();

	void refreshAliveTime() { _alivetime = clock(); }

	clock_t getAliveeTime()const { return clock() - _alivetime; }
private:
	MYSQL *_conn; 
	clock_t _alivetime;  
};